package com.example.boot.controller.Login;


import com.example.boot.domain.User;
import com.example.boot.mapper.simple_test.UserMapper;
import com.example.boot.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author laz
 * @date 2022/09/09 14:54
 */
@Service
public class IUserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public LoginDto login(User user) {
        LoginDto loginDto = new LoginDto();
        User login = userMapper.login(user);

        if (login == null){
            loginDto.setCode(400);
            loginDto.setMsg("账号或密码错误！");
            return loginDto;
        }
        String token= TokenUtil.sign(login);

        loginDto.setCode(200);
        loginDto.setMsg("登录成功!");
        loginDto.setUser(login);
        loginDto.setToken(token);
        return loginDto;
    }
}
